package fun.qu_an.minecraft.fabric.fzbbl.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ServerPistonCarvingEvents {
	public static final Event<PlayerCarving> PLAYER = EventFactory.createArrayBacked(PlayerCarving.class, listeners -> (world, pistonPos, unbreakableState, player) -> {
		for (PlayerCarving listener : listeners) {
			if (!listener.playerCarving(world, pistonPos, unbreakableState, player)) {
				return false;
			}
		}
		return true;
	});

	public static final Event<MachineCarving> MACHINE = EventFactory.createArrayBacked(MachineCarving.class, listeners -> (world, pistonPos, unbreakableState) -> {
		for (MachineCarving listener : listeners) {
			if (!listener.machineCarving(world, pistonPos, unbreakableState)) {
				return false;
			}
		}
		return true;
	});

	public interface PlayerCarving {
		boolean playerCarving(World world, BlockPos pistonPos, BlockState unbreakableState, PlayerEntity player);
	}

	public interface MachineCarving {
		boolean machineCarving(World world, BlockPos pistonPos, BlockState unbreakableState);
	}
}
